package sz.szsmk.citizencard.ui.activity;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.alipay.sdk.app.AuthTask;
import com.chenenyu.router.annotation.Route;

import org.greenrobot.eventbus.EventBus;

import java.util.Map;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.RealNameActivityBinding;
import sz.szsmk.citizencard.dialog.SuccessDialog;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonActivityComponent;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.AuthResult;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CheckIsChargeRes;
import sz.szsmk.citizencard.model.network.bean.response.FirstSearchUserLevelRes;
import sz.szsmk.citizencard.model.network.bean.response.IbaseBean;
import sz.szsmk.citizencard.model.network.dzbean.req.BaseRequest;
import sz.szsmk.citizencard.model.network.dzbean.req.PreAuthThirdRes;
import sz.szsmk.citizencard.model.network.dzbean.res.CheckIsRealName2Res;
import sz.szsmk.citizencard.model.network.dzbean.res.CheckIsRealNameRes;
import sz.szsmk.citizencard.model.network.dzbean.res.GetOpenIdRes;
import sz.szsmk.citizencard.model.network.dzbean.res.MessageEvent;
import sz.szsmk.citizencard.model.network.dzbean.res.QueryDzsmkAgreeMentRes;
import sz.szsmk.citizencard.mvp.contract.IRealNameContact;
import sz.szsmk.citizencard.mvp.presenter.RealNamePresenter;
import sz.szsmk.citizencard.ui.adapter.bean.AppHomeCardBean;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.ui.fragment.ElecCardSignDialog;
import sz.szsmk.citizencard.ui.newversion.config.Constants;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.Density;
import sz.szsmk.citizencard.util.JumpUtils;
import sz.szsmk.citizencard.util.MesageEventBus;
import sz.szsmk.citizencard.util.StringUtils;
import sz.szsmk.citizencard.widget.ScrollViewExt;
import zhy.com.highlight.HighLight;
import zhy.com.highlight.shape.BaseLightShape;
import zhy.com.highlight.shape.CircleLightShape;


/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/24 15:23
 * description: 实名认证
 */
@Route("RealNameActivity")
public class RealNameActivity extends IBaseActivity<RealNamePresenter, RealNameActivityBinding>
        implements IRealNameContact.IRealNameView, View.OnClickListener {

    TextView title;
    TextView btn1;
    TextView btn2;
    TextView btn3;
    TextView btn4;
    TextView btn5;
    LinearLayout bankCard;
    LinearLayout face;
    View infoName;
    View infoAll;
    TextView name;
    TextView level;
    TextView cardNo;
    AppHomeCardBean appHomeCardBean;
    LinearLayout infoMore;
    TextView cardTest;
    ScrollViewExt scroll;
    public static RealNameActivity mBActivity;
    private String channelId;
    private String openId;
    private int intoType = 0;
    private String chooseType = "";

    @Override
    protected int attachLayoutRes() {
        return R.layout.real_name_activity;
    }

    @Override
    protected void initInjector() {
        DaggerCommonActivityComponent.builder().
                appCompontent(DaggerApplication.getAppComponent()).build()
                .inject(this);
    }

    @Override
    protected void initViews() {
        initView();
        mBActivity = this;
        dataBinding.titleLayout.settingTitle.setText("实名认证");
        dataBinding.titleLayout.back.setOnClickListener(this);
        if(!TextUtils.isEmpty( getIntent().getStringExtra("intotype"))){
            intoType =  Integer.valueOf(getIntent().getStringExtra("intotype"));
        }else{
            intoType = getIntent().getIntExtra("intotype", 0);
        }
        chooseType = getIntent().getStringExtra("choosetype");
        dataBinding.infoMore.setOnClickListener(this);
        dataBinding.titleLayout.settingTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MessageEvent(MessageEvent.TO_DZSMK));
            }
        });
        appHomeCardBean = new AppHomeCardBean();

        dataBinding.scroll.setScrollViewListener(new ScrollViewExt.IScrollChangedListener() {
            @Override
            public void onScrolledToBottom() {
                if (dataBinding.scroll.isBottomEnd() && intoType == 1) {


                }
            }

            @Override
            public void onScrolledToTop() {

            }

            @Override
            public void onScroll(int t, int oldt) {

            }
        });

        //埋点
        MessageEvent message = new MessageEvent(MessageEvent.CODE_USERBEHAVIOR);
        message.setData(58);
        EventBus.getDefault().post(message);

    }


    private int scrollY = 0;
    private int scrollBottom = 0;
    private boolean faceshow;

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
    }

    @Override
    protected void updateViews() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }
    public boolean canScroll() {

        View child = scroll.getChildAt(0);
        if (child != null) {
            int childHeight = child.getHeight();
            return scroll.getHeight() < childHeight;
        }
        return false;
    }

    private void initBtn() {
        if (StringUtils.isBlank(appHomeCardBean.getCustName()) || StringUtils.isBlank(appHomeCardBean.getEcityCardNo())) {
            infoName.setVisibility(View.GONE);
            infoAll.setVisibility(View.GONE);
        } else {
            infoName.setVisibility(View.VISIBLE);
            infoAll.setVisibility(View.GONE);
            name.setText(appHomeCardBean.getCustName());
            level.setText(appHomeCardBean.getLevel() + "已认证");
            cardNo.setText(appHomeCardBean.getEcityCardNo());
        }
        String levelDesc = appHomeCardBean.getLevelDesc();
        if ("L3".equals(appHomeCardBean.getLevel())) {
            btn1.setBackgroundColor(getResources().getColor(R.color.transparent));
            btn1.setText("已认证");
            btn2.setBackgroundColor(getResources().getColor(R.color.transparent));
            btn2.setText("已认证");
            btn2.setEnabled(false);

            if(appHomeCardBean.getLevelDesc().contains("支付宝")){
                btn5.setBackgroundColor(getResources().getColor(R.color.transparent));
                btn5.setText("已认证");
                btn5.setEnabled(false);
            }else{
                btn5.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
                btn5.setText("");
                btn5.setEnabled(true);
            }

            if (appHomeCardBean.getLevelDesc().contains("银行卡")) {
                bankCard.setVisibility(View.VISIBLE);
//                face.setVisibility(View.VISIBLE);
                btn3.setBackgroundColor(getResources().getColor(R.color.transparent));
                btn3.setText("已认证");
                btn3.setEnabled(false);
            } else {
                btn3.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
                btn3.setText("");
                btn3.setEnabled(true);
            }

            if (appHomeCardBean.getLevelDesc().contains("人脸识别")) {
                btn4.setBackgroundColor(getResources().getColor(R.color.transparent));
                btn4.setText("已认证");
                bankCard.setVisibility(View.VISIBLE);
//                face.setVisibility(View.VISIBLE);
                btn4.setEnabled(false);
            } else {
                btn4.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
                btn4.setText("");
                if (intoType != 0) {

                    if(canScroll()){
                        Handler mHandler = new Handler();
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                remove(null);
                                scroll.fullScroll(ScrollView.FOCUS_DOWN);
                            }
                        });
                    }else {
                        btn4.post(new Runnable() {
                            @Override
                            public void run() {

                            }
                        });
                    }
                }
            }

        } else if ("L2".equals(appHomeCardBean.getLevel())) {
            btn1.setBackgroundColor(getResources().getColor(R.color.transparent));
            btn1.setText("已认证");
            btn2.setBackgroundColor(getResources().getColor(R.color.transparent));
            btn2.setText("已认证");
            btn2.setEnabled(false);
            btn3.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn3.setText("");
            btn4.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn4.setText("");
            btn5.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn5.setText("");
            if (intoType != 0) {
                if(canScroll()){
                    Handler mHandler = new Handler();
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            remove(null);
                            scroll.fullScroll(ScrollView.FOCUS_DOWN);
                        }
                    });
                }else{
                    btn4.post(new Runnable() {
                        @Override
                        public void run() {

                        }
                    });
                }
            }

        } else if ("L1".equals(appHomeCardBean.getLevel())) {
            btn1.setBackgroundColor(getResources().getColor(R.color.transparent));
            btn1.setText("已认证");
            btn2.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn2.setText("");
            btn3.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn3.setText("");
            btn4.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn4.setText("");
            btn5.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn5.setText("");
        } else {
            //网络不通
            btn1.setBackgroundColor(getResources().getColor(R.color.transparent));
            btn1.setText("已认证");
            btn2.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn2.setText("");
            btn3.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn3.setText("");
            btn4.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn4.setText("");
            btn5.setBackground(getResources().getDrawable(R.mipmap.real_name_btn));
            btn5.setText("");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.firstSearchUserLevel();
        Constant.isRealOpen = false;
    }


    public void click1(View v) {
        int id = v.getId();
        if (id == R.id.authentication_btn_1) {//凡是注册了都不会出现第一种情况
        } else if (id == R.id.authentication_btn_2) {
            JumpUtils.jump(this, "IDCardAuthenticationActivity", 0);
        } else if (id == R.id.authentication_btn_3) {
            if ("L1".equals(appHomeCardBean.getLevel())) {
                //跳转身份认证
                Toast.makeText(this, "请先进行身份证认证", Toast.LENGTH_SHORT).show();
            }
            if ("L2".equals(appHomeCardBean.getLevel())) {
                //跳转银行卡认证
                Constant.isRealOpen = true;
                mPresenter.getOpenId();
            }
            if ("L3".equals(appHomeCardBean.getLevel())) {
                Constant.isRealOpen = true;
                //立即开通
                JumpUtils.jumptoNatvie(this, Constants.SCANQRCODECHECKACTIVITY, 0, null);
            }
        } else if (id == R.id.authentication_btn_4) {
            if ("L1".equals(appHomeCardBean.getLevel())) {
                //跳转身份认证
                Toast.makeText(this, "请先进行身份证认证", Toast.LENGTH_SHORT).show();
            }
            if ("L2".equals(appHomeCardBean.getLevel())) {
                //跳转人脸识别
                String idCard = appHomeCardBean.getIdCard();
                String custName = appHomeCardBean.getCustName();
                Bundle bundle = new Bundle();
                bundle.putString(Constant.ID_CARD, idCard);
                bundle.putString(Constant.CUST_NAME, custName);
                MesageEventBus mesageEventBus = new MesageEventBus();
                mesageEventBus.setFaceName(custName);
                EventBus.getDefault().postSticky(mesageEventBus);
                JumpUtils.jumptoNatvie(this, "FaceAuthActivity", 0, bundle);
            }
            if ("L3".equals(appHomeCardBean.getLevel()) && !appHomeCardBean.getLevelDesc().contains("人脸识别")) {
                //跳转人脸识别
                String idCard = appHomeCardBean.getIdCard();
                String custName = appHomeCardBean.getCustName();
                Bundle bundle = new Bundle();
                bundle.putString(Constant.ID_CARD, idCard);
                bundle.putString(Constant.CUST_NAME, custName);
                MesageEventBus mesageEventBus = new MesageEventBus();
                mesageEventBus.setFaceName(custName);
                EventBus.getDefault().postSticky(mesageEventBus);
                JumpUtils.jumptoNatvie(this, "FaceAuthActivity", 0, bundle);
            }
        } else if (id == R.id.authentication_btn_5) {//直接判断L2  是L2  直接跳转支付宝
            if ("L2".equals(appHomeCardBean.getLevel()) || "L3".equals(appHomeCardBean.getLevel())) {
                //跳转支付宝 身份验证
                mPresenter.getAliString();
            } else {
                //跳转身份认证
                Toast.makeText(this, "请先进行身份证认证", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void firstSearchUserLevelSucc(AppHomeCardBean response) {
        appHomeCardBean = response;
        initBtn();
    }

    @Override
    public void firstSearchUserLevelFail(FirstSearchUserLevelRes response) {
//        mPresenter.firstSearchUserLevel();
    }

    @Override
    public void realNameCertificationSucc() {
        mPresenter.firstSearchUserLevel();
    }

    @Override
    public void realNameCertificationFail(IbaseBean response) {
        Toast.makeText(this, response.getMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void getOpenIdFail(GetOpenIdRes response) {

    }

    @Override
    public void getOpenIdSucc(GetOpenIdRes response) {
        showLoadingDialog();
        openId = response.getOpenId();
        L.e(Constant.TAG, "------------------获取到openid:" + openId);
        //根据openid查询用户协议
        mPresenter.queryDzsmkAgreement(openId);
    }

    @Override
    public void queryDzsmkAgreementFail(QueryDzsmkAgreeMentRes response) {
        dismissLoadingDialog();
    }

    @Override
    public void queryDzsmkAgreementSucc(QueryDzsmkAgreeMentRes response, String openId) {
        dismissLoadingDialog();
        channelId = response.getChannelId();
        mPresenter.checkIsOpenElecCard(openId);
    }

    @Override
    public void preAuthSucc(PreAuthThirdRes preAuthRes) {
        mPresenter.checkIsCharge();
    }

    @Override
    public void preAuthFail() {

    }

    @Override
    public void checkIsOpenElecCardFail(CheckIsRealNameRes preAuthRes) {

    }

    @Override
    public void checkIsOpenElecCardSucc(CheckIsRealNameRes preAuthRes) {
        String isRealName = preAuthRes.getData().getIsRealName();
        if (isRealName.equals("0")) {
            ElecCardSignDialog dialog = new ElecCardSignDialog();
            dialog.setAction(0);
            dialog.show(this.getFragmentManager(), null);
        } else {
//            mPresenter.checkIsCharge();
            mPresenter.preAuth(channelId, openId);

        }
    }

    @Override
    public void checkIsOpenElecCardSucc2(CheckIsRealName2Res preAuthRes) {
        String isRealName = preAuthRes.getData().getIsRealName();
        if (isRealName.equals("0")) {
            ElecCardSignDialog dialog = new ElecCardSignDialog();
            dialog.setAction(0);
            dialog.show(this.getFragmentManager(), null);
        } else {
            mPresenter.preAuth(channelId, openId);

        }
    }

    @Override
    public void checkIsChargeFail() {

    }

    @Override
    public void checkIsChargeSucc(CheckIsChargeRes ibaseBean) {
        String code = ibaseBean.getCode();
        if (code.equals("0000")) {
            String isReCharge = ibaseBean.getData().getIsReCharge();
            if (isReCharge.equals("1")) {
                JumpUtils.jump(this, "dzsmk", 0);
            } else if (isReCharge.equals("0")) {
                ElecCardSignDialog dialog = new ElecCardSignDialog();
                dialog.setAction(1);
                dialog.show(this.getFragmentManager(), null);
            }
        } else {
            final SuccessDialog dialog = new SuccessDialog(this, ibaseBean.getMessage());
            dialog.show();
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    dialog.cancel();
                }
            }.start();
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.back) {
            finish();
        } else if (id == R.id.info_more) {
            Bundle bundle = new Bundle();
            bundle.putString(Constant.ID_CARD, appHomeCardBean.getIdCard());
            bundle.putString(Constant.ID_NAME, appHomeCardBean.getCustName());
            JumpUtils.gotoNeedGesture(this, "elecCitizenCard", bundle);
        }

        click1(v);
    }

    private HighLight mHightLight;


    public void showIdCardTipGhfView() {
        mHightLight = new HighLight(RealNameActivity.this)//
                .anchor(findViewById(R.id.lin_info))
                .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
                .intercept(true)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
                .addHighLight(R.id.authentication_btn_2, R.layout.ydl2ghf_showtip,
                        new OnCustomTopCallback(Density.dip2px(RealNameActivity.this, 40),
                                Density.dip2px(RealNameActivity.this, 185)),
                        new CircleLightShape(Density.dip2px(RealNameActivity.this, 0),
                                Density.dip2px(RealNameActivity.this, 0)));


        mHightLight.show();

    }

    public void showIdCardTipGjjView() {
        mHightLight = new HighLight(RealNameActivity.this)//
                .anchor(findViewById(R.id.lin_info))
                .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
                .intercept(true)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
                .addHighLight(R.id.authentication_btn_2, R.layout.ydl2gjj_showtip,
                        new OnCustomTopCallback(Density.dip2px(RealNameActivity.this, 40),
                                Density.dip2px(RealNameActivity.this, 185)),
                        new CircleLightShape(Density.dip2px(RealNameActivity.this, 0),
                                Density.dip2px(RealNameActivity.this, 0)));


        mHightLight.show();

    }

    public void showIdCardTipSbView() {
        mHightLight = new HighLight(RealNameActivity.this)//
                .anchor(findViewById(R.id.lin_info))
                .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
                .intercept(true)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
                .addHighLight(R.id.authentication_btn_2, R.layout.ydl2sb_showtip,
                        new OnCustomTopCallback(Density.dip2px(RealNameActivity.this, 40),
                                Density.dip2px(RealNameActivity.this, 185)),
                        new CircleLightShape(Density.dip2px(RealNameActivity.this, 0),
                                Density.dip2px(RealNameActivity.this, 0)));


        mHightLight.show();

    }

    public void showFaceTipGhfView() {

        mHightLight = new HighLight(RealNameActivity.this)//
                .anchor(findViewById(R.id.lin_info))
                .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
                .intercept(true)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
                .addHighLight(R.id.authentication_btn_4, R.layout.ydl3ghf_showtip,
                        new OnCustomTopCallback(Density.dip2px(RealNameActivity.this, 30 + scrollBottom - 145),
                                Density.dip2px(RealNameActivity.this, 185)),
                        new BaseLightShape() {
                            @Override
                            protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
                                viewPosInfoRectF.inset(0, 0);
                            }

                            @Override
                            protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
                                Canvas canvas = new Canvas(bitmap);
                                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                                paint.setDither(true);
                                paint.setAntiAlias(true);
                                if (blurRadius > 0) {
                                    paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
                                }
                                RectF rectF = viewPosInfo.rectF;
                                Log.d("circlerectf", "------->" + rectF);
//                                rectF.top = rectF.top-scrollY+135*2;
//                                rectF.bottom = rectF.bottom-scrollY+135*2;
                                canvas.drawCircle(rectF.left + (rectF.width() / 2), rectF.top + (rectF.height() / 2),
                                        Math.max(rectF.width(), rectF.height()) / 2, paint);
                            }
                        });


        mHightLight.show();

    }

    public void showFaceTipGjjView() {

        mHightLight = new HighLight(RealNameActivity.this)//
                .anchor(findViewById(R.id.lin_info))
                .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
                .intercept(true)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
                .addHighLight(R.id.authentication_btn_4, R.layout.ydl3gjj_showtip,
                        new OnCustomTopCallback(Density.dip2px(RealNameActivity.this, 30 + scrollBottom - 145),
                                Density.dip2px(RealNameActivity.this, 185)),
                        new BaseLightShape() {
                            @Override
                            protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
                                viewPosInfoRectF.inset(0, 0);
                            }

                            @Override
                            protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
                                Canvas canvas = new Canvas(bitmap);
                                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                                paint.setDither(true);
                                paint.setAntiAlias(true);
                                if (blurRadius > 0) {
                                    paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
                                }
                                RectF rectF = viewPosInfo.rectF;
                                Log.d("circlerectf", "------->" + rectF);
//                                rectF.top = rectF.top-scrollY+135*2;
//                                rectF.bottom = rectF.bottom-scrollY+135*2;
                                canvas.drawCircle(rectF.left + (rectF.width() / 2), rectF.top + (rectF.height() / 2),
                                        Math.max(rectF.width(), rectF.height()) / 2, paint);
                            }
                        });


        mHightLight.show();

    }

    public void showFaceTipSbView() {

        mHightLight = new HighLight(RealNameActivity.this)//
                .anchor(findViewById(R.id.lin_info))
                .autoRemove(false)//设置背景点击高亮布局自动移除为false 默认为true
                .intercept(true)//设置拦截属性为false 高亮布局不影响后面布局的滑动效果 而且使下方点击回调失效
                .addHighLight(R.id.authentication_btn_4, R.layout.ydl3sb_showtip,
                        new OnCustomTopCallback(Density.dip2px(RealNameActivity.this, 30 + scrollBottom - 145),
                                Density.dip2px(RealNameActivity.this, 185)),
                        new BaseLightShape() {
                            @Override
                            protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
                                viewPosInfoRectF.inset(0, 0);
                            }

                            @Override
                            protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
                                Canvas canvas = new Canvas(bitmap);
                                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                                paint.setDither(true);
                                paint.setAntiAlias(true);
                                if (blurRadius > 0) {
                                    paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
                                }
                                RectF rectF = viewPosInfo.rectF;
                                Log.d("circlerectf", "------->" + rectF);
//                                rectF.top = rectF.top-scrollY+135*2;
//                                rectF.bottom = rectF.bottom-scrollY+135*2;
                                canvas.drawCircle(rectF.left + (rectF.width() / 2), rectF.top + (rectF.height() / 2),
                                        Math.max(rectF.width(), rectF.height()) / 2, paint);
                            }
                        });


        mHightLight.show();

    }

    public void clickIdCard(View view) {
        if (mHightLight.isShowing())//如果开启next模式
        {
            Bundle bundle = new Bundle();
            bundle.putInt("intotype", intoType);
            bundle.putString("choosetype", chooseType);
            JumpUtils.jumptoNatvie(this, "IDCardAuthenticationActivity", 0, bundle);

        }
    }

    public void clickFace(View view) {
        if (mHightLight.isShowing())//如果开启next模式
        {
            String idCard = appHomeCardBean.getIdCard();
            String custName = appHomeCardBean.getCustName();
            Bundle bundle = new Bundle();
            bundle.putString(Constant.ID_CARD, idCard);
            bundle.putString(Constant.CUST_NAME, custName);
            bundle.putInt("intotype", intoType);
            bundle.putString("choosetype", chooseType);
            MesageEventBus mesageEventBus = new MesageEventBus();
            mesageEventBus.setFaceName(custName);
            EventBus.getDefault().postSticky(mesageEventBus);
            JumpUtils.jumptoNatvie(this, "FaceAuthActivity", 0, bundle);
            faceshow = true;
        }
    }

    public void remove(View view) {
        if (mHightLight != null && !faceshow) {
            mHightLight.remove();
        }
    }

    @Override
    public void getAliStringSuccess(String st) {
        alipayLogin(st);
    }


    private void alipayLogin(final String authInfo) {
        dismissLoadingDialog();
        Runnable authRunnable = new Runnable() {
            @Override
            public void run() {
                // 构造AuthTask 对象
                AuthTask authTask = new AuthTask(RealNameActivity.this);
                // 调用授权接口，获取授权结果
                Map<String, String> result = authTask.authV2(authInfo, true);

                Message msg = new Message();
                msg.what = SDK_AUTH_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };

        // 必须异步调用
        Thread authThread = new Thread(authRunnable);
        authThread.start();
    }
    private static final int SDK_AUTH_FLAG = 2;
    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @SuppressWarnings("unused")
        public void handleMessage(Message msg) {
            switch (msg.what) {

                case SDK_AUTH_FLAG: {
                    showLoadingDialog();
                    @SuppressWarnings("unchecked")
                    AuthResult authResult = new AuthResult((Map<String, String>) msg.obj, true);
                    String resultStatus = authResult.getResultStatus();
                    String alipayOpenId = authResult.getAlipayOpenId();
                    String authCode = authResult.getAuthCode();
                    if (TextUtils.equals(resultStatus, "9000") && TextUtils.equals(authResult.getResultCode(), "200")) {

                        BaseRequest baseRequest = new BaseRequest();
                        baseRequest.setAuthCode(authCode);
                        baseRequest.setAccessToken(ACache.get(RealNameActivity.this).getAsString("access_token"));
                        baseRequest.setCertNo(appHomeCardBean.getIdCard());
                        mPresenter.getAlicode(baseRequest);

                        dismissLoadingDialog();
                    } else {
                        // 其他状态值则为授权失败
                        Toast.makeText(RealNameActivity.this,
                                "授权失败", Toast.LENGTH_SHORT).show();
                        dismissLoadingDialog();
                    }
                    break;
                }
                default:
                    break;
            }
        }
    };

    @Override
    public void getAlipayUserInfo(BaseBean bean) {
        Toast.makeText(this,bean.getMessage(),Toast.LENGTH_LONG).show();
        btn5.setBackgroundColor(getResources().getColor(R.color.transparent));
        btn5.setText("已认证");
        btn5.setEnabled(false);
    }

    @Override
    public void getAlipayUserInfoFail(BaseBean bean) {
        Toast.makeText(this,bean.getMessage(),Toast.LENGTH_LONG).show();
    }


    private void initView() {
        title = findViewById(R.id.setting_title);
        btn1 = findViewById(R.id.authentication_btn_1);
        btn2= findViewById(R.id.authentication_btn_2);
        btn3= findViewById(R.id.authentication_btn_3);
        btn4= findViewById(R.id.authentication_btn_4);
        btn5= findViewById(R.id.authentication_btn_5);
        bankCard= findViewById(R.id.bank_card);
        face= findViewById(R.id.face);
        infoName= findViewById(R.id.info_name);
        infoAll= findViewById(R.id.info_all);
        name= findViewById(R.id.name);
        level= findViewById(R.id.level);
        cardNo= findViewById(R.id.card_no);
        infoMore= findViewById(R.id.info_more);
        cardTest= findViewById(R.id.card_test);
        scroll= findViewById(R.id.scroll);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);
    }
}
